<template>
  <div class="login fromBox">
    <h1>登录</h1>
    <p><label for="username">用户名</label></p>
    <el-input id='username' placeholder="请输入内容" v-model="userData.username" clearable> </el-input>
    <p><label for="password">密码</label></p>
    <el-input id='password' placeholder="请输入密码" v-model="userData.password" show-password></el-input>
    <p><el-button type="primary" plain @click="login()">登录</el-button></p>
    <p class="toggle">
      <a href="javasript:void(0)" id="forgetPW">忘记密码</a>
      &nbsp;
      <a href="javasript:void(0)" id="goRegister" @click='$router.push("/register")'>注册</a>
    </p>

    <h1 id="sysTitle" @click='$router.push("/stuSystem")'><a href="javascript:void(0)" >Sam9029 Student System</a></h1>
  </div>
</template>

<script>
// @ is an alias to /src
import api from '@/http/api/apis'

export default {
  data() {
    return {
      userData:{
        username:'',
        password:''
      }
      
    };
  },
  methods:{
    async login(){
      const {data} = await api.loginApi.login(this.userData);
      console.log(data);
      if(data.status){
        this.$notify.success({
          title: "成功提示",
          message: data.message
        });

        //设置token
        localStorage.setItem('token',data.token);        

        //登录成功后 跳转到系统页面
        this.$router.push("/stuSystem")

      }else{
        this.$notify.error({
          title:'错误提示',
          message:data.message
        })
      }
    }
  },
};
</script>

<style scoped lang='scss' src="../assets/login.scss">

